#include "Model.h"
#include <assimp\Importer.hpp>
#include <assimp\postprocess.h>
#include <assimp\scene.h>

#include "pg2_indexbuffer.h"
#include "vertexbuffer.h"

#include "Node.h"
#include "mesh.h"
using namespace ns;

void Model::AddMeshNode(aiNode* node, Node* base){
	
	Node* n = new Node();

	for(int i = 0;i<node->mNumMeshes;i++){
		
		Mesh* m = new Mesh(scene->mMeshes[node->mMeshes[i]] , renderer);
		
		n->AddChildNode(m);
	}

	base->AddChildNode(n);

	for(int i = 0;i<node->mNumChildren;i++){
		AddMeshNode(node->mChildren[i],n);
	}

}


Model::Model(const std::string file,Renderer* _renderer, Node* base){
	Assimp::Importer importer;
	scene = importer.ReadFile(file,0x8|0x2);
	renderer = _renderer;

	AddMeshNode(scene->mRootNode,base);
}
